package com.onpositive.nlp.inflector;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashSet;

import edu.smu.tspell.wordnet.Synset;
import edu.smu.tspell.wordnet.SynsetType;
import edu.smu.tspell.wordnet.WordNetDatabase;

public class SimplePOFParser {

	
	public static String getCore(String s1) {
		String[] split = s1.split("_");
		LinkedHashSet<String>sm=new LinkedHashSet<String>(Arrays.asList(split));
		for (String s:split){
			if (Character.isDigit(s.charAt(0))){
				continue;
			}
			
			if (isAdjective(s)){
				sm.remove(s);
			}
		}
		StringBuilder bld=new StringBuilder();
		for (String s:sm){
			bld.append(s);
			bld.append('_');
		}
		if (bld.length()>0&& bld.charAt(bld.length()-1)=='_'){
			bld.deleteCharAt(bld.length()-1);
		}
		return bld.toString();		
	}
	
	static HashMap<String,Boolean>s=new HashMap<String, Boolean>();
	static HashMap<String,Boolean>nouns=new HashMap<String, Boolean>();
	static HashMap<String,Boolean>verbs=new HashMap<String, Boolean>();
	
	public static boolean isAdjective(String s1){
		if (s.containsKey(s1)){
			return s.get(s1);
		}
		Synset[] synsets = WordNetDatabase.getFileInstance().getSynsets(s1, SynsetType.ADJECTIVE);
		boolean b = synsets.length>0;
		s.put(s1, b);
		return b;
	}
	public static boolean isNoun(String s1){
		if (nouns.containsKey(s1)){
			return nouns.get(s1);
		}
		Synset[] synsets = WordNetDatabase.getFileInstance().getSynsets(s1, SynsetType.NOUN);
		boolean b = synsets.length>0;
		nouns.put(s1, b);
		return b;
	}
	
	public static boolean isVerb(String s1){
		if (verbs.containsKey(s1)){
			return verbs.get(s1);
		}
		Synset[] synsets = WordNetDatabase.getFileInstance().getSynsets(s1, SynsetType.VERB);
		boolean b = synsets.length>0;
		verbs.put(s1, b);
		return b;
	}
}
